<template>
	<view class="full-page" v-if="totalPage">
		
	</view>
	<view v-else>
		<view class="show-content">
			<!-- #ifndef MP-WEIXIN -->
			<u-navbar :autoBack="true" title="我的橱窗" bgColor="#fff" :fixed="true" >
				<view slot="right">
					<text style="padding: 5px 16px;border-radius: 12px;background: #45C4B0;font-size: 10px;color: #fff;" @click="$go('/showcase/showcase/add')">新增</text>
				</view>
			</u-navbar>
			<!-- #endif -->
			
			<!-- #ifdef MP-WEIXIN -->
			<view class="head" @click="$go('/showcase/showcase/add')">
				<image :src="'/images/showcase_icon.png' | formatImgUrl" mode=""></image>
				新增橱窗
			</view>
			<view class="" style="text-align: center;color: #9E9E9E;font-size: 10px;padding: 10px 0;">
				橱窗展示顺序与个人展示顺序同步，让您的展示更加个性化
			</view>
			<!-- #endif -->
			
			
			<view class="display-flex just-between filter-top">
				<view class="left">
					<view class="display-flex fix-nav">
						<view @click="clickNav(0)" :class="navIndex==0?'active':''">
							已开放
						</view>
						
						<view @click="clickNav(1)" :class="navIndex==1?'active':''">
							未开放
						</view>
					</view>
				</view>
				
				<view class="right display-flex" @tap="showFilter=true">
					<text class="label">当前状态：</text>
					
					<text class="val display-flex" v-if="is_paidan == 0">
						立即接单
					</text>
					<text class="val val2 display-flex" v-if="is_paidan == 1">
						需要排稿
					</text>
					<text class="val val3 display-flex" v-if="is_paidan == 2">
						暂停接单
					</text>
				</view>
			</view>
		</view>

		
		
		<!-- <HM-dragSorts ref="dragSorts" :list="goodList" :longTouch="false" :feedbackGenerator="true" :rowHeight="125"
			@onclick="onclick" @change="change" @confirm="confirm"></HM-dragSorts> -->
		
		<block v-if="navIndex==0">
			<view class="empytView" v-if="goodList.length<=0">
				<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
				<!-- <view>- 空列表 -</view> -->
			</view>
			<view class="showcase_item" v-for="(item,index) in goodList" :name="item.id">
				<view class="showcase_head">
					<image :src="'/images/tip_icon.png ' | formatImgUrl" mode=""></image>
					<text class="tit">{{item.title}}</text>
			
					<view class="tip" v-if="item.status==0">
						正在审核
					</view>
					<!-- <view class="tip suc" v-if="item.status==1">
						审核通过
					</view> -->
					<view @tap.stop="shibai(item.refuse_msg)" class="tip err" v-if="item.status==2">
						审核失败
					</view>
			
					<view class="jubox" style="padding: 10rpx;top: 0;" @click="bom_show(item)">
						<image :src="'/images/bao.png' | formatImgUrl"  class="jubox" mode=""></image>
					</view>
				</view>
			
				<view class="showcase_wrap" @tap="look_data(item)">
					<view class="wrap_item">
						<image :src="'/images/re_list1.png' | formatImgUrl" mode="">作品类型：</image>
						<text>{{item.type_name || ''}}</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list2.png' | formatImgUrl" mode="">起拍单数：</image>
						<text>{{item.start_shooting  || ''}} 单</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list3.png' | formatImgUrl" mode="">用户评分：</image>
						<text>{{item.rank  || ''}} 星</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list4.png' | formatImgUrl" mode="">费用标准：</image>
						<text>{{Number(item.price).toFixed(0)}}币/{{item.word_count || ''}}</text>
					</view>
					
					<!-- <image :src="'/images/show-icon4.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-if="item.is_w==1"></image> -->
					<image :src="'/images/show-icon1.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-if="item.status==1"></image>
					<!-- <image :src="'/images/show-icon2.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-else-if="item.status==0"></image> -->
					<image :src="'/images/show-icon3.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-else-if="item.status==2"></image>
				</view>
				<view class="bottom">
					<view class="user">
						<image :src="'/images/order_num.png' | formatImgUrl" mode=""></image>
						<text>下单人数:{{item.buy_num}}人</text>
					</view>
					<view class="sub2" v-if="item.status==0">
						去查看
					</view>
					<view class="sub" @click="look_data(item)" v-if="item.status==1">
						看数据
					</view>
					<view class="sub2" @click="toEdit(item)" v-if="item.status==2">
						去编辑
					</view>
				</view>
			</view>
		</block>
		<block v-if="navIndex==1">
			<view class="empytView" v-if="goodList2.length==0">
				<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
				<!-- <view>- 空列表 -</view> -->
			</view>
			<view class="showcase_item" v-for="(item,index) in goodList2" :name="item.id">
				<view class="showcase_head">
					<image :src="'/images/tip_icon.png ' | formatImgUrl" mode=""></image>
					<text class="tit">{{item.title}}</text>
					
					<block v-if="(item.type_class && item.type_class != '0') || item.type == 6">
						<view class="tip" v-if="item.status==0">
							正在审核
						</view>
						<!-- <view class="tip suc" v-if="item.status==1">
							审核通过
						</view> -->
						<view @tap.stop="shibai(item.refuse_msg)" class="tip err" v-if="item.status==2">
							审核失败
						</view>
					</block>
					
			
					<view class="jubox" style="padding: 10rpx;top: 0;" @click="bom_show(item)">
						<image :src="'/images/bao.png' | formatImgUrl"  class="jubox" mode=""></image>
					</view>
				</view>
			
				<view class="showcase_wrap" @tap="look_data(item)">
					<view class="wrap_item">
						<image :src="'/images/re_list1.png' | formatImgUrl" mode="">作品类型：</image>
						<text>{{item.type_name || ''}}</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list2.png' | formatImgUrl" mode="">起拍单数：</image>
						<text>{{item.start_shooting  || ''}} 单</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list3.png' | formatImgUrl" mode="">用户评分：</image>
						<text>{{item.rank  || ''}} 星</text>
					</view>
					<view class="wrap_item">
						<image :src="'/images/re_list4.png' | formatImgUrl" mode="">费用标准：</image>
						<text>{{Number(item.price).toFixed(0)}}币/{{item.word_count || ''}}</text>
					</view>
					
					<block v-if="(item.type_class && item.type_class != '0') || item.type == 6">
						<!-- <image :src="'/images/show-icon4.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-if="item.is_w==1"></image> -->
						<image :src="'/images/show-icon1.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-if="item.status==1"></image>
						<!-- <image :src="'/images/show-icon2.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-else-if="item.status==0"></image> -->
						<image :src="'/images/show-icon3.png' | formatImgUrl" mode="aspectFit" class="iconimg" v-else-if="item.status==2"></image>
					</block>
				</view>
				<view class="bottom">
					<view class="user">
						<image :src="'/images/order_num.png' | formatImgUrl" mode=""></image>
						<text>下单人数:{{item.buy_num}}人</text>
					</view>
					<block v-if="item.type_class && item.type_class != '0'">
						<view class="sub2" v-if="item.status==0">
							去查看
						</view>
						<view class="sub" @click="look_data(item)" v-if="item.status==1">
							看数据
						</view>
						<view class="sub2" @click="toEdit(item)" v-if="item.status==2">
							去编辑
						</view>
					</block>
					<block v-else>
						<view class="sub" @click="toEdit(item)">
							去编辑
						</view>
					</block>
				</view>
			</view>
		</block>
		

		<u-popup :show="show" @close="close">
			<view class="mask" v-if="info">
				<view v-if="info.status > 0" class="matop" @click="goToreport">
					<view class="matxt">
						编辑橱窗
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<view class="matop" :style="{'margin-top': info.status > 0 ? '-10px' : 0}" @click="show=false,openSet=true" v-if="info.status == 1 && navIndex == 0">
					<view class="matxt" >
						调整排序
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<!-- <view class="matop" style="margin-top: -10px;">
					<view class="matxt" @click="$go('/pages/find/report?id=' + info.id + '&type='+info.type+'&newtype=1')">
						举报
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view> -->
				<view class="matop" style="margin-top: -10px;" @click="delItem()">
					<!-- <image :src="'/images/jing.png'  | formatImgUrl" class="mapic" mode=""></image> -->
					<view class="matxt" >
						删除橱窗
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>

				<view class="qubox" @click="show = false">
					取消
				</view>
			</view>
		</u-popup>

		<view class="model">
			<u-modal :show="modalShow" :title="title" :content='content' :showConfirmButton='true'
				:showCancelButton='true' @confirm='modalShow = false' @cancel="modalShow=false"></u-modal>
		</view>


		<!-- <u-modal :show="openSet" title="调整排序" :show-cancel-button="true" width="520rpx" confirm-color="#3D3D3D" @confirm='onConfirm' @cancel="openSet=false">
			<view class="slot-content">
				<view class="desc">
					将本条橱窗调整至<input type="text" v-model="weigh">位
				</view>
				<view class="intro">
					受到影响的橱窗将自动后移一位
				</view>
			</view>
		</u-modal> -->
		
		<u-popup mode="center" :show="openSet" @close="openSet=false">
			<view class="mask11" style="padding-left: 0;padding-right: 0;padding-bottom: 0;padding-top: 23px;">
				<view class="matitle">
					<text>调整排序</text>
				</view>
				<view class="slot-content">
					<view class="desc">
						将本条橱窗调整至<input type="text" v-model="weigh">位
					</view>
					<view class="intro">
						受到影响的橱窗将自动后移一位
					</view>
				</view>
				<view class="quque" style="margin-top: 30rpx;">
					<view class="quli" @click="openSet = false">
						取消
					</view>
					<view class="quli quactive" @click="onConfirm">
						确定
					</view>
				</view>
			</view>
		</u-popup>
	
	
		<u-popup :show="showFilter" @close="showFilter=false">
			<view class="mask">
				<view class="matop" @tap="setType(0)">
					<view class="matxt" >
						立即接单
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<view class="matop" style="margin-top: -10px;" @tap="setType(1)">
					<view class="matxt" >
						需要排稿
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<view class="matop" style="margin-top: -10px;" @tap="setType(2)">
					<view class="matxt" >
						暂停接单
					</view>
					<image :src="'/images/rarr.png'  | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<view class="qubox" @click="showFilter = false">
					取消
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import HMDragSorts from '@/components/HM-dragSorts/HM-dragSorts.vue'
	export default {
		data() {
			return {
				show: false,
				modalShow: false,
				title: '确认删除',
				content: '此操作不可逆',

				page: 1,
				page2: 1,
				list: {},
				list2: {},
				goodList: [],
				goodList2: [],
				info: null,
				openSet: false,
				weigh: '',
				gid: '',
				totalPage: true,
				navIndex: 0,
				showFilter: false,
				is_paidan: '',
				userInfo: this.$db.get('userInfo')
			};
		},
		components:{
			HMDragSorts
		},
		onShow() {
			this.is_paidan = this.userInfo.is_paidan
			
			this.page = 1;
			this.list = {};
			this.goodList = [];
			
			this.page2 = 1;
			this.list2 = {};
			this.goodList2 = [];
			this.getList()
			this.getList2()
			
			if(uni.getStorageSync('sel_types')){
				uni.removeStorageSync('sel_types')
			}
			if(uni.getStorageSync('selectedItem')){
				uni.removeStorageSync('selectedItem')
			}
			if(uni.getStorageSync('list')){
				uni.removeStorageSync('list')
			}
		},
		// 上拉加载
		onReachBottom() {
			if (this.navIndex == 0 && this.list.current_page < this.list.last_page) {
				this.page++; // 页数加一，加载下一页数据
				this.getList();
			}
			
			if (this.navIndex == 1 && this.list2.current_page < this.list2.last_page) {
				this.page2++; // 页数加一，加载下一页数据
				this.getList2();
			}
		},
		methods: {
			leftClick(){
				uni.navigateBack({
					delta: 1
				});
			},
			clickNav(num){
				this.navIndex = num
				
				// this.page = 1;
				// this.list = {};
				// this.goodList = [];
				// this.getList()
			},
			// 设置状态
			setType(type){
				this.$api.default.request('good/good_set', {
					is_pai: type
				}).then((res) => {
					if (res.code == 1) {
						this.is_paidan = type
						this.$common.successToShow(res.msg, () => {
							this.showFilter=false
						})
					}else{
						this.$common.errorToShow(res.msg, () => {
							this.showFilter=false
						})
					}
				})
			},
			onConfirm(){
				console.log('onConfirm');
				if(!this.weigh){
					this.$common.errorToShow('请输入排序位置')
					return
				}
				
				this.$api.default.request('good/good_weight', {
					weigh: this.weigh,
					gid: this.gid
				}).then((res) => {
					if (res.code == 1) {
					
						this.$common.successToShow(res.msg, () => {
							this.weigh = ''
							this.openSet = false;
							this.page = 1;
							this.getList()
						})
					}else{
						this.$common.errorToShow(res.msg, () => {
							this.weigh = ''
							this.openSet = false;
						})
					}
				})
			},
			look_data(item) {
				if(item.status == 0 || item.status == 2){
					return
				}
				
				uni.navigateTo({
					url: '/showcase/showcase/datails?id=' + item.id + '&type=1'
				})

			},
			bom_show(item) {
				this.gid=item.id
				
				this.show = true
				this.info = item
			},
			goToreport() {

				this.show = false
				uni.navigateTo({
					url: '/showcase/showcase/edit?id=' + this.info.id +'&type_name='+this.info.type_name
				})
			},
			toEdit(item){
				uni.navigateTo({
					url: '/showcase/showcase/edit?id=' + item.id +'&type_name='+ item.type_name
				})
			},
			close() {
				this.show = false
			},
			shibai(msg) {
				console.log(msg, 888);
				if(!msg){
					return
				}
				
				this.$common.errorToShow(msg)
			},
			getList() {
				// this.totalPage = true
				this.$api.default.request('good/list', {
					page: this.page,
					status: 1
				}).then((res) => {
					if (res.code) {
						this.list = res.data
						if (res.data.current_page > 1) {
							res.data.data.forEach((item) => {
								this.goodList.push(item)
							})
						} else {
							this.goodList = res.data.data
						}
						
					}
					
					this.totalPage = false
				})
			},
			
			getList2() {
				// this.totalPage = true
				this.$api.default.request('good/list', {
					page: this.page2,
					status: 2
				}).then((res) => {
					if (res.code) {
						this.list2 = res.data
						if (res.data.current_page > 1) {
							res.data.data.forEach((item) => {
								this.goodList2.push(item)
							})
						} else {
							this.goodList2 = res.data.data
						}
					}
					
					this.totalPage = false
				})
			},
			delItem() {

				var that = this
				uni.showModal({
					cancelText: '取消',
					confirmText: '确定',
					confirmColor: '#45C4B0',
					content: '确认删除此橱窗吗？',
					success: function(res) {
						if (res.confirm) {

							that.$api.default.request('good/delGood', {
								id: that.info.id
							}, 'POST').then((res) => {
								if (res.code == 1) {

									that.show = false;

									that.$common.successToShow(res.msg, () => {
										that.page = 1
										that.getList()
									})
								}
							})

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	.filter-top{
		width: 100%;
		padding-top: 40px;
		box-sizing: border-box;
		background-color: #fff;
		
		.left{
			align-items: flex-end;
			
			view{
				color:#999;font-size:16px;margin-right: 16rpx;
			}
			
			.active{
				color:#3D3D3D;font-weight:700;font-size:20px;
			}
		}
		
		.label{
			font-family: 思源黑体;
			font-size: 10px;
			color: #3D3D3D;
		}
		.val{
			width: 50px;
			height: 16px;
			border-radius: 4px;
			background: rgba(69, 196, 176, 0.15);
			justify-content: center;
			font-family: 思源黑体;
			font-size: 10px;
			color: #45C4B0;
		}
		
		.val2{
			background: rgba(153, 153, 153, 0.15);
			color: #999999;
		}
		
		.val3{
			background: rgba(237, 50, 50, 0.15);
			color: #ED3232;
		}
	}
	
	/deep/.u-modal{
		background: #fff;
	}
	
	/deep/.u-modal__title{
		font-family: Source Han Sans CN;
		font-size: 16px!important;
		font-weight: bold;
		color: #3D3D3D!important;
	}
	
	/deep/.u-modal__button-group__wrapper--confirm{
		background: rgba(#45C4B0, 0.05);
		color: #3D3D3D;
	}
	
	.slot-content{
		text-align: center;
	}
	.slot-content .desc{
		font-family: Source Han Sans CN;
		font-size: 12px;
		color: #3D3D3D;
		margin-bottom: 30rpx;
		
		input{
			display: inline-block;vertical-align: middle;
			width: 56rpx;
			margin: 0 5rpx;
			border-bottom: 1rpx solid #D8D8D8;
			text-align: center;
		}
	}
	
	.slot-content .intro{
		font-family: Source Han Sans CN;
		font-size: 10px;
		color: #999999;
	}
	
	page {
		background: rgba(242, 245, 242, 1);
	}

	.show-content {
		// min-height: 100rpx;
		background: #fff;
		padding: 30rpx;
		padding-bottom: 0 !important;
		box-sizing: border-box;
		/* #ifdef APP */
		min-height: calc(var(--status-bar-height) +  35px);
		padding-top: 60px;
		/* #endif */
		width: 100%;
		overflow-x: hidden;

		.empytView {
			padding-top: 200rpx;
		}
		.head {

			border-radius: 16rpx;
			opacity: 1;
			box-sizing: border-box;
			border: 1rpx solid rgba(216, 216, 216, 0.3);
			display: flex;
			justify-content: center;
			align-items: center;
			padding: 18rpx 0;
			font-size: 24rpx;
			font-weight: normal;
			color: #999999;

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 12rpx;
			}
		}
	}

	.showcase_item {
		padding: 24rpx 30rpx;
		box-sizing: border-box;
		background: #fff;
		margin-bottom: 20rpx;
		position: relative;
		
		.iconimg{
			position: absolute;
			right: 0;
			top: 50%;
			transform: translate(0%,-60%);
			width: 134px;
			height: 134px;
		}

		.showcase_head {
			display: flex;
			position: relative;
			align-items: center;

			image {
				width: 32rpx;
				height: 32rpx;
				object-fit: cover;
				margin-right: 8rpx;
			}

			.tit {
				font-size: 28rpx;
				font-weight: bold;
				color: #3D3D3D;
			}

			.tip {
				font-size: 20rpx;
				font-weight: normal;
				color: #999999;
				padding: 2rpx 8rpx;
				background: rgba(153, 153, 153, 0.15);
				border-radius: 8rpx;
				margin-left: 16rpx;
			}

			.jubox {
				position: absolute;
				top: 6rpx;
				right: 0rpx;
				width: 32rpx;
				height: 32rpx;
				z-index: 99;
				// border: 1px dashed #eeeeee;
			}

			.suc {
				background: rgba(69, 196, 176, 0.15);
				color: #45C4B0;
			}

			.err {
				color: #D63636;
				background: rgba(214, 54, 54, 0.15);
			}

		}

		.showcase_wrap {
			margin-top: 28rpx;
			display: grid;
			grid-gap: 28rpx 24rpx;
			grid-template-columns: repeat(auto-fill, 300rpx);
			padding-bottom: 20rpx;
			border-bottom: 1px solid rgba(153, 153, 153, 0.1);
			overflow: hidden;
			box-sizing: border-box;

			.wrap_item {
				display: flex;
				align-items: center;
				font-size: 20rpx;
				color: #999999;

				image {
					width: 24rpx;
					height: 24rpx;
					object-fit: cover;
					margin-right: 4rpx;
				}
			}
		}

		.bottom {
			padding-top: 24rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.user {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 24rpx;
				color: #999999;

				image {
					width: 32rpx;
					height: 32rpx;
					border-radius: 50%;
					object-fit: cover;
					margin-right: 4rpx;
				}
			}

			.sub {
				border-radius: 24rpx;
				padding: 10rpx 32rpx;
				background: #45C4B0;
				font-size: 20rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
			
			.sub2 {
				border-radius: 24rpx;
				padding: 10rpx 32rpx;
				background: #999;
				font-size: 20rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}

	.mask {
		background: #ffffff;
		border-top-left-radius: 8px;
		border-top-right-radius: 8px;
		overflow: hidden;

		.matop {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 40rpx 68rpx;
			margin-bottom: 20rpx;
			border-bottom: 1px solid rgba(153, 153, 153, 0.1);
			background-color: #ffffff;

			.mapic {
				width: 40rpx;
				height: 40rpx;
				flex-shrink: 0;
			}

			.matxt {
				flex-grow: 1;
				font-size: 28rpx;
				// padding: 0 16rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
			}
		}

		.qubox {
			border-top: 20rpx solid rgba(153, 153, 153, 0.1);
			line-height: 120rpx;
			text-align: center;
			font-size: 28rpx;
			font-weight: bold;
			letter-spacing: 0em;
			color: #3D3D3D;
			height: 120rpx;
			opacity: 1;
			background: #FFFFFF;
			margin-top: -10px;
		}
	}

	.model {
		background-color: #fff;

		.u-popup__content {
			background-color: #FFFFFF !important;

			.u-modal__content__text {
				text-align: center;
			}
		}
	}
	
	.mask11 {
		background-color: #ffffff;
		width: 534rpx;
		border-radius: 8px;
		padding: 20rpx 30rpx;
	
		.matitle {
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			letter-spacing: 0em;
			color: #3D3D3D;
			padding-bottom: 6rpx;
			line-height: 46rpx;
		}
	
		.matxt {
			font-size: 24rpx;
			font-weight: normal;
			text-align: center;
			letter-spacing: 0em;
			color: #999999;
			line-height: 34rpx;
			padding-bottom: 50rpx;
		}
	
		.quque {
			display: flex;
			align-items: center;
			border-top: 1px solid rgba(153, 153, 153, 0.1);
			
	
			.quli {
				width: 50%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 32rpx;
				font-weight: normal;
				letter-spacing: 0em;
				color: #3D3D3D;
			}
	
			.quactive {
				background: rgba(69, 196, 176, 0.05);
			}
		}
	}
</style>